package keeto.com.vn.classified.task;

import java.io.IOException;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.network.IProtocol;
import keeto.com.vn.classified.request.ProductBySellerRequest;
import keeto.com.vn.classified.response.ProductBySellerRespone;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
public class TaskGetProductBySeller extends AbstractTask{
	private String CategoryType;
	private String ItemId;
	private int pageNumber;
	private String CategoryId;
	private int guarantyId;
	private int pageLimit;
	private String SellerName;
	private String NotInPCodes;

	public TaskGetProductBySeller(ClassifiedListener listener, ClassifiedCore core,String categoryType, String categoryId, String SellerName,String ItemId,int guarantyId, int pageNumber, int pageLimit, String NotInPCodes) {
		super(listener, core);
		this.CategoryType = categoryType;
		this.CategoryId = categoryId;
		this.SellerName = SellerName;
		this.ItemId = ItemId;
		this.pageNumber = pageNumber;
		this.pageLimit = pageLimit;
		this.guarantyId = guarantyId;
		this.NotInPCodes = NotInPCodes;
	}
	@Override
	public void run() throws ClientProtocolException, JSONException, IOException {
		ProductBySellerRequest request = new ProductBySellerRequest();
		request.setCategoryType(CategoryType);
		request.setCategoryId(CategoryId);
		request.setSellerName(SellerName);
		request.setGuaranteeId(guarantyId);
		request.setItemId(ItemId);
		request.setPageNumber(pageNumber);
		request.setPageLimit(pageLimit);
		request.setNotInPCodes(NotInPCodes);
		ProductBySellerRespone response = json.getProductbySeller(request);
		
		for (ClassifiedListener listener : listeners) {
			listener.finishGetProductBySeller(response.getReturnCode(), response.getListItemEntity(), response.isHasmore());
		}
	}
	@Override
	public void timeoutCallback() {
		for (ClassifiedListener l : core.copyAndReconstructListeners(listener)) {
			l.finishGetProductBySeller(IProtocol.STATUS_CODE_CONNECTION_TIMEOUT_502, null,false);
		}
	}
	
}
